
package com.rt.schedulenew.utils.base;
import java.lang.reflect.Method;
import com.rt.schedulenew.utils.annotation.FieldName;
import java.beans.PropertyDescriptor;
import org.apache.commons.lang3.ArrayUtils;
import java.lang.reflect.Field;
public class LogUtil
{
    public static String compareObject(Object oldBean, Object newBean) {
        String str = "";
        Object pojo1 = oldBean;
        Object pojo2 = newBean;
        try {
            Class clazz = pojo1.getClass();
            Field[] fields = clazz.getDeclaredFields();
            Field[] fields_super = clazz.getSuperclass().getDeclaredFields();
            Field[] fields_all = (Field[])ArrayUtils.addAll(fields, (Object[])fields_super);
            int i = 1;
            for (Field field : fields_all) {
                if (!"serialVersionUID".equals(field.getName())) {
                    if (!isAcronym(field.getName())) {
                        PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
                        Method getMethod = pd.getReadMethod();
                        Object o1 = (getMethod.invoke(pojo1) != null) ? getMethod.invoke(pojo1) : "空";
                        Object o2 = (getMethod.invoke(pojo2) != null) ? getMethod.invoke(pojo2) : "空";
                        if (!o1.toString().equals(o2.toString())) {
                            FieldName fieldName = field.getAnnotation(FieldName.class);
                            String fieldNameStr = (fieldName == null) ? field.getName() : fieldName.value();
                            if (i != 1) {
                                str += "；";
                            }
                            str = str + fieldNameStr + "：" + o1 + "=>" + o2;
                            ++i;
                        }
                    }
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }
    
    public static boolean isAcronym(String word) {
        for (int i = 0; i < word.length(); ++i) {
            char c = word.charAt(i);
            if (Character.isLowerCase(c)) {
                return false;
            }
        }
        return true;
    }
}
